<?php

namespace App\Console\Commands;

use App\Models\ModelNumberSpecification;
use App\Models\Product;
use App\Models\ProductCenter;
use App\Models\ProductJobType;
use Illuminate\Console\Command;

class AddProductCenter extends Command
{
    /**
     * The name and signature of the console command.
     * php artisan command:addproductcenter
     * @var string
     */
    protected $signature = 'command:addproductcenter';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     *
     * @return int
     */

    public function handle()
    {
        $price_arr = [
            1=>	30,
            2=> 45,
            5=>	60,
            7=>	45,
            10=>0
        ];
        $list = ModelNumberSpecification::all();
        foreach($list as $k=>$v){
            $product_id = $v->product_id;
            $job_type_list = ProductJobType::where('product_id',$product_id)->get();
            foreach($job_type_list as $kk=>$vv){
                $where = [
                    'product_id'=>$product_id,
                    'model_number_id'=>$v->model_number_id,
                    'specification_id'=>$v->specification_id,
                    'job_type_id'=>$vv->job_type_id
                ];
                $price = $price_arr[$vv->job_type_id];
                ProductCenter::updateOrCreate($where,[$where,'price'=>$price]);
            }
        }
    }
}
